package com.yubest.rabbitmq.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping(value = "/send/direct")
    public Object send() {
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("test.direct.queue", "hello rabbitmq" + i);
        }
        return "ok";
    }

    @GetMapping(value = "/send/work")
    public Object send2() {
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("test.work.queue", "hello rabbitmq" + i);
        }
        return "ok";
    }

    @GetMapping(value = "/send/fanout")
    public Object send3() {
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("test.fanout.exchange", "", "hello rabbitmq" + i);
        }
        return "ok";
    }

    @GetMapping(value = "/send/routingDirect")
    public Object send4() {
        rabbitTemplate.convertAndSend("test.routing.direct.exchange", "test.routing.direct.key1", "key1 -> hello rabbitmq");
        rabbitTemplate.convertAndSend("test.routing.direct.exchange", "test.routing.direct.key2", "key2 -> hello rabbitmq");
        rabbitTemplate.convertAndSend("test.routing.direct.exchange", "test.routing.direct.key3", "key3 -> hello rabbitmq");
        rabbitTemplate.convertAndSend("test.routing.direct.exchange", "test.routing.direct.key4", "key4 -> hello rabbitmq");
        return "ok";
    }

    @GetMapping(value = "/send/routingTopic")
    public Object send5() {
        rabbitTemplate.convertAndSend("test.routing.topic.exchange", "test.routing.topic.key", "key -> hello rabbitmq");
        rabbitTemplate.convertAndSend("test.routing.topic.exchange", "test.routing.topic.key.1", "key.1 -> hello rabbitmq");
        rabbitTemplate.convertAndSend("test.routing.topic.exchange", "test.routing.topic.key.2.1", "key.2.1 -> hello rabbitmq");
        return "ok";
    }
}
